package pcjavanet.mobilesell.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import pcjavanet.mobilesell.model.Authorizations;
import pcjavanet.mobilesell.model.Employee;
import pcjavanet.mobilesell.model.Module;
import pcjavanet.mobilesell.model.PageBean;
import pcjavanet.mobilesell.model.QryCondition;
import pcjavanet.mobilesell.service.AuthorizationsService;
import pcjavanet.util.LogUtil;

import com.opensymphony.xwork2.ActionSupport;
@Namespace("/authorizations")
@Controller
@Scope("prototype")
@ParentPackage("json-default")
@Results({
	@Result(name = "success", location = "/view/Authorizations.jsp"),
	@Result(name = "input", location = "/view/Authorizations.jsp")
})

public class AuthorizationsAction  extends ActionSupport {

  @Resource
  private AuthorizationsService authorizationsService;
  private   java.lang.Integer dbid ;
  private   java.lang.Integer refModuleDbid ;
  private   java.lang.Integer refEmployeeDbid ;
  private   java.lang.Integer operatetype ;
  private   java.util.Date createDate ;
  private int start  ;
  private int limit  ;
  private int totalProperty  ;
  private boolean success = true ;
  private String  info ;
  private List<Authorizations>  authorizationsPageBeans  ;
  private List<Module>  modulePageBeans  ;
  public    java.lang.Integer getDbid() {
   	return this.dbid;
  }
  public void setDbid(  java.lang.Integer  dbid) {
   	 this.dbid=dbid;
  }
  public    java.lang.Integer getRefModuleDbid() {
   	return this.refModuleDbid;
  }
  public List<Module> getModulePageBeans() {
	return modulePageBeans;
}
public void setModulePageBeans(List<Module> modulePageBeans) {
	this.modulePageBeans = modulePageBeans;
}
public void setRefModuleDbid(  java.lang.Integer  refModuleDbid) {
   	 this.refModuleDbid=refModuleDbid;
  }
  public    java.lang.Integer getRefEmployeeDbid() {
   	return this.refEmployeeDbid;
  }
  public void setRefEmployeeDbid(  java.lang.Integer  refEmployeeDbid) {
   	 this.refEmployeeDbid=refEmployeeDbid;
  }
  public    java.lang.Integer getOperatetype() {
   	return this.operatetype;
  }
  public void setOperatetype(  java.lang.Integer  operatetype) {
   	 this.operatetype=operatetype;
  }
  public    java.util.Date getCreateDate() {
   	return this.createDate;
  }
 
public void setCreateDate(  java.util.Date  createDate) {
   	 this.createDate=createDate;
  }
  public  void setStart(int start) {
   	 this.start = start;
  }
  public  void setLimit(int limit) {
   	 this.limit = limit;
  }
  public  void setTotalProperty(int totalProperty) {
   	 this.totalProperty = totalProperty;
  }
  public  void setAuthorizationsPageBeans(List<Authorizations> authorizationsPageBeans){
   	 this.authorizationsPageBeans =authorizationsPageBeans  ;
  }
  public  int getStart( ) {
   	 return this.start;
  }
  public  int getLimit( ) {
   	 return this.limit;
  }
  public  int getTotalProperty( ) {
   	 return this.totalProperty;
  }
  public    List<Authorizations> getAuthorizationsPageBeans(){
   	 return this.authorizationsPageBeans   ;
  }
  public  String getInfo( ) {
   	 return this.info;
  }
  public  void setInfo(String info){
   	 this.info = info ;
  }
  public  boolean getSuccess( ) {
   	 return this.success;
  }
  public  void setSuccess(boolean success){
   	 this.success = success ;
  }

  @Action(value="insertAuthorizations",results = {@Result(name = "success", type = "json")})
  public String  insertAuthorizations() throws Exception{
   	success = false ;
   	info = "" ;
  	Authorizations bean = new Authorizations();
  	bean.setRefModuleDbid(this.refModuleDbid); 
  	bean.setRefEmployeeDbid(this.refEmployeeDbid); 
  	bean.setOperatetype(this.operatetype); 
  	bean.setCreateDate(this.createDate); 
	authorizationsService.insert(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_INSERT , Authorizations.MODULE_ID );
	}
   	success = true ;
   	info = "Add Successful" ;
   	return SUCCESS;
  }

  @Action(value="queryAuthorizations",results = {@Result(name = "success", type = "json")})
  public String  queryAuthorizations() throws Exception{
  	Authorizations bean = new Authorizations();
  	bean.setDbid(this.dbid); 
  	bean.setRefModuleDbid(this.refModuleDbid); 
  	bean.setRefEmployeeDbid(this.refEmployeeDbid); 
  	bean.setOperatetype(this.operatetype); 
  	bean.setCreateDate(this.createDate); 
	authorizationsService.selectByPrimaryKey(bean);
   	return SUCCESS;
  }

  @Action(value="updateAuthorizations",results = {@Result(name = "success", type = "json")})
  public String  updateAuthorizations() throws Exception{
   	success = false ;
   	info = "" ;
  	Authorizations bean = new Authorizations();
  	bean.setDbid(this.dbid); 
  	bean.setRefModuleDbid(this.refModuleDbid); 
  	bean.setRefEmployeeDbid(this.refEmployeeDbid); 
  	bean.setOperatetype(this.operatetype); 
  	bean.setCreateDate(this.createDate); 
  	bean =authorizationsService.selectByPrimaryKey(bean);
  	bean.setDbid(this.dbid); 
  	bean.setRefModuleDbid(this.refModuleDbid); 
  	bean.setRefEmployeeDbid(this.refEmployeeDbid); 
  	bean.setOperatetype(this.operatetype); 
  	bean.setCreateDate(this.createDate); 
	authorizationsService.updateByPrimaryKeySelective(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_UPDATE , Authorizations.MODULE_ID );
	}
   	success = true ;
   	info = "Update Successful" ;
   	return SUCCESS;
  }

  @Action(value="deleteAuthorizations",results = {@Result(name = "success", type = "json")})
  public String  deleteAuthorizations() throws Exception{
  	Authorizations bean = new Authorizations();
  	bean.setDbid(this.dbid); 
  	bean.setRefModuleDbid(this.refModuleDbid); 
  	bean.setRefEmployeeDbid(this.refEmployeeDbid); 
  	bean.setOperatetype(this.operatetype); 
  	bean.setCreateDate(this.createDate); 
	authorizationsService.deleteByPrimaryKey(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_DELETE , Authorizations.MODULE_ID );
	}
   	return SUCCESS;
  }

  @Action(value="listAuthorizations",results = {@Result(name = "success", type = "json")})
  public String  listAuthorizations() throws Exception{
 	QryCondition qry = RequestUtil.getQryCondition(   (javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST)); 	PageBean pageBean = new PageBean();
	pageBean.setPageSize( limit );
	pageBean.setStartCount( start );
	totalProperty =authorizationsService.getTotalRecords( qry, pageBean );
	authorizationsPageBeans =authorizationsService.getOnePageBeans( qry, pageBean );
   	return SUCCESS;
  }
  
  @Action(value="listAllModule",results = {@Result(name = "success", type = "json")})
  public String   listAllModule() throws Exception{
	  modulePageBeans =  authorizationsService.listAllModule();
	  return SUCCESS;
  }

  @Action("index")
  public String index() throws Exception{
   	return SUCCESS;
  }

}
